package thread;

import message.BaseMessage;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

/**
 * 客户端监听线程.
 *
 * @author 张天羿
 */
public class ClientThread extends Thread {
    private Socket client;

    public ClientThread(Socket client) {
        super();
        this.client = client;
    }

    public void run() {

        try {
            while (true) {
                ObjectInputStream objectInputStream = new ObjectInputStream(client.getInputStream());
                BaseMessage baseMessage = (BaseMessage) objectInputStream.readObject();
                System.out.println("收到数据" + baseMessage);
                baseMessage.selfExecute();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }


}